import crypto from 'crypto';
const hash = crypto.createHash('sha256');
hash.update('password1234');
console.log("散列运算希望输出:"+hash.digest('hex'));
crypto.randomBytes(16, (err, buf) => {
    if (err) throw err;
    console.log("生成随机字节:"+buf.toString('hex'));
    });
    const algorithm = 'aes-256-cbc';
const key = crypto.randomBytes(32);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, key,iv);
let encrypted = cipher.update('Hello, this is a secret message', 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log("用16进制的方法输出加密后的字符串:"+encrypted);
const decipher = crypto.createDecipheriv(algorithm, key, iv);
    let decrypted = decipher.update(encrypted, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    console.log("将加密内容还远为原始信息:"+decrypted);
